<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <title>动态组件</title>
</head>
<body>
<div id="app">
    <div>
        <span @click="tab('first')">1</span>
        <span @click="tab('second')">2</span>
        <span @click="tab('third')">3</span>
    </div>
    <component :is="currentTabComponent"></component>
</div>

<script>
     Vue.component('first', {
        template: '<div>这是第一tab</div>'
    })

      Vue.component('second', {
        template: '<input type="text" />'
    })

       Vue.component('third', {
        template: '<div>这是第三tab</div>'
    })
    new Vue({
        el: '#app',
        data: function (){
            return {
                currentTabComponent: 'first'
            }
        },
        methods: {
            tab(t) {
                this.currentTabComponent = t
            }
        }
    })


</script>
</body>
</html>